<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="${res_app}/css/wuxi.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>
<title>申报书审核</title>
<style type="text/css">
.button_orange { 
	height:25px; font-size:12px; color:#cc3300; border:1px #cc9933 solid; 
	background:url(${res}/images/button_orange.gif); padding:0 15px; *padding:0 10px;
	_padding:0 10px; cursor: pointer;
}
</style>
</head>
<body>
<%-- <security:authorize ifAnyGranted="A_AUTH_SCS">
 <cpt:helpTips key="prpapproveTips4scs" id="prpapproveTips4scs"></cpt:helpTips>
 <div class="clear_h10"></div>
 </security:authorize> --%>
	<input type="hidden" id="childDiv" class="thickbox" />
		<form method="post" id="mainForm">
			<input type="hidden" id="prpCodes" name="prpCodes" value="" />
			<input type="hidden" id="type" name="type" value="" />
		</form>
	<div class="soBox">
		<div class="detail ico_search">
			<table>
				<tr>
					<td rowspan="2"><strong>检索条件：</strong>
					</td>
				
					<td>
						<cpt:search key="prpApprove_backup"  repeatColumn="3" displayCount="6" leftStyle="width:100px"></cpt:search>
					</td>
				
				</tr>
				<tr>
				<td>
					<div class="clear_h10"></div>
					<input type='button' id='searchBt' class="button_an" value='查询' />
				</td>
				</tr>
				
			</table>
		</div>
	</div>
	<div class="clear_h10"></div>
	<div>
		<div id='TopBarMnt'></div>
		<table id='dataGrid'></table>
		<div id='dataBar'></div>
	</div>
	<script type="text/javascript">
	var irisGrid = new IrisGrid("dataGrid", "dataBar", 'TopBarMnt');
	var prcWin = new progressWin("${res}");//初始化遮罩层
	
	var getSelOpt = function() {
		var g = "";
		$("input:checkbox[id^=jqg_dataGrid_]").each(function(i, obj) {
			if (obj.checked) {
				g += "," + obj.id.replace("jqg_dataGrid_", "");
			}
		});
		if (g != "") {
			g = g.substring(1);
		}
		return $.trim(g);
	};
	
	function showApproveDialog(type, gridObj, selectIdArray, recordRows){
		var prpCodes= getSelOpt();
		if(recordRows==''){
			prpCodes=selectIdArray+'';
		}
		if(prpCodes==""){
			scmError("请选择一条记录");
			return false;
		}
		
		if(type=="approve"){
			
			if(!checkSelect(selectIdArray)){
				return false;
			}
		}
		
		if(type=="approve"){
				
				var prpnum = prpCodes.split(",").length;
				$("#prpCodes").val(prpCodes);
				$("#type").val(type);
				var options = {
						beforeSubmit : function() {
							prcWin.openWin();//打开遮罩层
							$("#approve").attr("disabled",true);
						}, // 表单提交前的回调函数
						success : function(msg) {
							prcWin.closeWin();
							scmSuccess(msg);
							irisGrid.getGridDom().jqGrid("refresh",0);//0是本页1是首页
							$("#approve").attr("disabled",false);
						},// 表单成功提交后的回调函数
						error : function() {
							scmError("操作失败,请联系系统管理员");
							prcWin.closeWin();
							$("#approve").attr("disabled",false);
						},
						url: "${ctx}/tech-ctr/"+type
					};
				if(confirm("是否确认此"+prpnum+"份申报书?")){
					var url="${ctx}/tech-ctr/openbackupapprovedialog?category=A&prpCodes="+prpCodes+"&type="+type+"&TB_iframe=true&height=250&width=410";
					var title="申报审核意见（最多为500字）";
					showThickBox(url,title);
					//$("#mainForm").ajaxSubmit(options);
				}
				else{
					return;
				}
			
		}else{
			if(prpCodes.split(",").length>1){
				scmError("退回操作限制只能单个退回");
				return false;
			}
			
			var url="${ctx}/tech-ctr/openbackupapprovedialog?category=A&prpCodes="+prpCodes+"&type="+type+"&TB_iframe=true&height=250&width=410";
			var title="申报审核意见（最多为500字）";
			showThickBox(url,title);	
		}
		
	}
	
	function checkSelect(selectArray){
		var checked = 1;
		$("#approve").removeAttr("disabled");//去除该属性
		var grantcodeStr = "";
		var statYearStr = "";
		for(var i=0;i<selectArray.length;i++){
			var status=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"13");
			var flagCan=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"14");
			var grantCode=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"15");
			var statyear=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"16");
			if(status=="05"){
				scmWarn("您所选择的这"+selectArray.length+"份申报书中有部分申报书已受理，不允许重复确认!");
				checked = 0;
				break;
			}else if(status=='04'&&flagCan=="0") {
				scmWarn("您所选择的这"+selectArray.length+"份申报书中有部分申报书的正式PDF未生成，请在生成之后再选择该申报书进行受理操作");
				checked = 0;
				break;
			}else{
				grantcodeStr += ","+grantCode;
				statYearStr += ","+statyear;
			}
		}
		if(checked==0){
			return false;
		}else if(grantcodeStr!=""){
			return checklimitInfo(grantcodeStr,statYearStr);
		}
		return true;
	}
	
	function closeDialog(){
		tb_remove();
	}

	
		/** 表格初始化**/
		//loadIrisGrid("${res}");
		function buildGrid() {
			
			var columnAttrList = new Array();
			 
			columnAttr = new ColumnAttr("单位名称", "org_name","org_name", 6, "left", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);
 
			columnAttr = new ColumnAttr("单位联系人", "psn_name","psn_name", 2, "center", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("邮箱", "psn_name","psn_name", 2, "center", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("联系电话", "psn_name","psn_name", 2, "center", true);
			columnAttrList.push(columnAttr);
			
			
			columnAttr = new ColumnAttr("提交时间", "submitDate", "submit_date", 3,"left", true);
			columnAttrList.push(columnAttr);
			

		
			columnAttr = new ColumnAttr("收/授权原因", "comment", "comment", 3,"center", false);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("操作", "caozuo", "caozuo", 3,"center", false);
			columnAttrList.push(columnAttr);
			irisGrid.setColumnAttrs(columnAttrList);
			//打印汇总表功能关闭  
			  irisGrid.setToolsBar([ 
			   {
				  id : 'addm',
				  name : '新增中介机构' ,
				  trigger : orgYesClick
				}
			   ]);
			 
			irisGrid.setUrl("${ctx}/tech-ctr/backup-deprive-list?stat_year=${param.stat_year}");//查询url
			irisGrid.setCaption("暂写");
			irisGrid.setDefaultSortName("award_jsht_time");//默认排序字段
			irisGrid.setDefaultSortorder("desc");
			irisGrid.setWidth(978);//整个表格宽度
			irisGrid.setCheckAble(false);//表格左边是否要复选框
			irisGrid.setShowRowIndex(true);//是否显示行号
			irisGrid.setQueryBox('searchBt',"prpApprove_backup");//查询条件 按钮名，查询条件function_key
			irisGrid.setLoadComplete(setGray);
			irisGrid.onSelectAll = function(selectid,isSelect){//全选事件
				checkSelectAll();
			};
			/*
			irisGrid.onSelectRow = function(selectid,isSelect){//审核项目
				//alert(selectid);
				//selectid = encodeURIComponent(selectid);
				//alert(selectid);
				var backFlag = $("#"+selectid+"_backFlag").val();
			   // if(backFlag == 'YES')return;
			
			
				var posCode = $("#posCode_"+selectid).val();
				var grantCode = $("#grantCode_"+selectid).val();
				var subGrantCode = $("#subGrantCode_"+selectid).val();
				var curDate = "${curDate}";
				
				var pcode= $("#prp_Code_"+selectid).val();

	
				//判断该项目是否有退回过
				var backDate = $("#backDate_"+selectid).val();
				var isback = 0;
				if(backDate!=null&&backDate!=''){
					isback = 1;
				}
				var roleId = "${roleId}";
				var off_code = "${off_code}";
				var dialogUrl = "${ctx}/tech-ctr/openbackupapprovedialog?category=A&off_code="+off_code+"&backFlag="+backFlag+"&roleId="+roleId+"&isback="+isback+"&curDate="+curDate+"&prpCodes="+pcode+"&posCode="+posCode+"&grantCode="+grantCode+"&subGrantCode="+subGrantCode+"&TB_iframe=true&height=250&width=410";
			    window.open(dialogUrl,'newwin');
			};
			*/
			irisGrid.build();
		}
		function showApproveDialog(pcode,prpcode){
			var selectid= pcode;
			var curDate = "${curDate}";
			var roleId = "${roleId}";
			var off_code = "${off_code}";
			var posCode = $("#posCode_"+selectid).val();
			var grantCode = $("#grantCode_"+selectid).val();
			var subGrantCode = $("#subGrantCode_"+selectid).val();
			var status = $("#status_"+selectid).text();
			//var dialogUrl = "${ctx}/tech-ctr/openbackupapprovedialog?category=A&off_code="+off_code+"&roleId="+roleId+"&status="+status+"&curDate="+curDate+"&prpCodes="+pcode+"&posCode="+posCode+"&grantCode="+grantCode+"&subGrantCode="+subGrantCode+"&TB_iframe=true&height=250&width=410";
			var dialogUrl = "${ctx}/tech-ctr/openbackupapprovedialog?category=A&off_code="+off_code+"&status="+status+"&prpCodes="+prpcode+"&posCode="+posCode+"&grantCode="+grantCode+"&subGrantCode="+subGrantCode+"&TB_iframe=true&height=250&width=410";
		    window.open(dialogUrl,'newwin');
			
		}  
		
		function orgYesClick(){
			tb_show("新增中介机构",
					"${ctx}/tech-ctr/org_selector_ds?flag=main&jshtType=add&TB_iframe=true&height=270&width=700",
					false);
		}
		
		function depriveAction(psnCode,orgCode){
				url="${ctx}/tech-ctr/backupDepriveDialog?orgCode="+encodeURIComponent(orgCode)+"&psnCode="+encodeURIComponent(psnCode)+"&TB_iframe=true&height=250&width=410";
				tb_show("中介权限收回原因（最多为500字）", url, false);
		}
		function approveAction(pcode,prpcode,orgCode){
			var selectid= pcode;
			var curDate = "${curDate}";
			var roleId = "${roleId}";
			var off_code = "${off_code}";
			var posCode = $("#posCode_"+selectid).val();
			var grantCode = $("#grantCode_"+selectid).val();
			var subGrantCode = $("#subGrantCode_"+selectid).val();
			var status = $("#status_"+selectid).text();
				url="${ctx}/tech-ctr/backupApproveDialog?prpCodes="+encodeURIComponent(prpcode)+"&orgCode="+encodeURIComponent(orgCode)+"&TB_iframe=true&height=250&width=410";
				tb_show("中介权限授予原因（最多为500字）", url, false);
		}
		
		function checkSelectAll(){
			$("input:checkbox[id^=jqg_dataGrid_]").each(function(i, obj) {
				if($(obj).attr("disabled")){
					$(obj).attr("checked",false);
				}
			});
		}
		jQuery(function() {
			if("${prpstatus}"!=""){
				try{
				$("#_dyn_criteria2_field").val("prpstatus");
				_dyn_ShowCriteriaTag(document.getElementById("_dyn_criteria2_field"));
				$("#prpstatus").val("${prpstatus}");
				}catch(ee){}
			}
			
			if("${audie_date}"!=""){
				try{
				$("#_dyn_criteria2_field").val("audie_date");
				_dyn_ShowCriteriaTag(document.getElementById("_dyn_criteria2_field"));
				$("#audie_date").val("${audie_date}");
				}catch(ee){}
			}
			
			buildGrid();
		//	if($.browser.msie && $.browser.version<8)
			//	$("#return").addClass("button_orange").css("margin-left","166px");
		//	else
			//	$("#return").addClass("button_orange").css("margin-left","157px");
			
		});
		/** 表格初始化**/
		
		function setGray(){
			var role = '<c:out value="${role}"/>';
			$("input:checkbox[id^=jqg_dataGrid_]").each(function(i, obj) {
				var id = $(obj).attr("id").replace("jqg_dataGrid_", "");
				var status = $.trim($("#status_"+id).html());
				if(role=='danwei'){
					if(status=="01"){
						$(obj).attr("disabled",false);
						$("#agree_"+id).show();
						$("#refuse_"+id).show();
					}else{
						$(obj).attr("disabled",true);
						$("#agree_"+id).hide();
						$("#refuse_"+id).hide();
					}
				}else if(role=='chushi'){
					if(status=="04" || status=="03"){
						$(obj).attr("disabled",false);
						$("#agree_"+id).show();
						$("#refuse_"+id).show();
					}else if(status=="05"){
						$(obj).attr("disabled",false);
						$("#agree_"+id).show();
						$("#refuse_"+id).show();
					}else{
						$(obj).attr("disabled",true);
						$("#agree_"+id).hide();
						$("#refuse_"+id).hide();
					}
				}
			});
		}
		
		function cleanQueryBox(){
			$("[id^='_dyn_criteria'][id$='_c']", "#prpApprove_search4org").each(function(){
				$(this).children().each(function(){
					$(this).val('');
				});
			});
		}
		
		function viewComment(des3Prpcode){
			var url="${ctx}/tech-ctr/audit-comment-view?posCode="+des3Prpcode+"&TB_iframe=true&height=390&width=720";
			var title="收/授权记录";
			showThickBox(url,title);	
		}
		
		/**检查选中项目限项设置**/
		function checklimitInfo(grantcodeStr,statYearStr){
			var checked = 1;
			var msg = "";
			if(grantcodeStr!=""&&'${limitinfo}'!=''){
				grantcodeStr = grantcodeStr.substring(1);
				statYearStr = statYearStr.substring(1);
				var linfoArr = '${limitinfo}'.split(",");
				for(var i=0;i<linfoArr.length;i++){
					var sublinfoArr = linfoArr[i].split("##");//grant_code##grant_name##limit_count##approved_count
					var grantCode1 = sublinfoArr[0];
					var grantName = sublinfoArr[1];
					var limitCount = sublinfoArr[2];
					var approvedCount = sublinfoArr[3];
					var statYear = sublinfoArr[4];
					var grantcodeArr = grantcodeStr.split(",");
					var statYearArr = statYearStr.split(",");
					var selected = 0;
					for(var j=0;j<grantcodeArr.length;j++){
						if(grantcodeArr[j]==grantCode1 && statYearArr[j]==statYear){
							selected++;
						}
					}
					if(selected>0){
					var checkNum = parseInt(approvedCount)+selected;
						if(checkNum>parseInt(limitCount)){
							checked = 0;
							var shen = parseInt(limitCount,10)-parseInt(approvedCount,10);
							if(shen<0){
								shen = 0;
							}
							msg = "您单位申报"+statYear+"年度"+grantName+"类别的项目仅能申报"+limitCount+"项，目前已经上报了"+approvedCount+"项，还能上报"+shen+"项.";
							break;
						}
					}
				}
			}
			if(checked>0){
				return true;
			}
			scmWarn(msg, null, 7000);
			return false;
			
		}

		//审核页面调用该方法刷新页面
		function search(){
			$("#searchBt").click();
		}
		
		
		/**查看单位信息*/
		function orgInfoView(orgCode){
			//$("#orgCode").val(orgCode);
			//$("#mainForm").submit();
			tb_show("查看单位信息","${ctx}/orgmanage/verifyorg/org-info-view?orgCode=" + orgCode
					+ "&TB_iframe=true&height=460&width=950", false);
		}
		
		/**查看单位信息*/
		function recOrgInfoView(orgCode){
			tb_show("查看单位信息",ctx + "/orgmanage/verifyorg/recorg-info-view?orgCode=" + orgCode
					+ "&TB_iframe=true&height=460&width=950", false);
		}
		
		function showReportDialog(){
			var searchString=jQuery('#dataGrid').jqGrid('getGridParam','postData')['searchString'];
			tb_show("打印汇总表","${ctx}/tech-ctr/list-for-report"+"?searchString="+encodeURIComponent(searchString)+"&TB_iframe=true&height=460&width=1024", false);
		}
		
		function viewPrpCheckResults(prpCode){
			tb_show("规则检查结果","${ctx}/tech-ctr/prp-check-result?prpCode=" + prpCode
					+ "&TB_iframe=true&height=460&width=824", false);
		}
		
		function showPrpSimilarView(prpCode){
			tb_show("","${ctx}/tech-ctr/prp-similar-list?prpCode=" + prpCode +"&TB_iframe=true&height=460&width=820",false);
		}
	</script>
</body>
</html>